package com.study.patterns.proxy.dynamic.asm.base;


import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
 * Created by tan on 2017/6/22.
 */
public class ClassWriterAdapter {
	private ClassWriter writer;

	public ClassWriterAdapter(ClassWriter writer) {
		this.writer = writer;
	}

	public MethodVisitor visitMethod(int access, String name, String desc,
									 String signature, String[] exceptions) {
		MethodVisitor methodVisitor = writer.visitMethod(access, name, desc,
				signature, exceptions);
		if (name.equals("<init>")) {
			return new InitMethodAdapter(Opcodes.ASM5, methodVisitor);
		} else if (name.equals("setName")) {
            return new SetMethodAdapter(Opcodes.ASM5,methodVisitor);
		} else if (name.equals("getName")) {
			return new GetMethodAdapter(Opcodes.ASM5, methodVisitor);
		} else {
			return null;
		}
	}
}
